import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Artcile from '../views/Artcile.vue';



Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    component: Home,
    //子路由
    children:[
      {
        path: 'artcile',
        component: Artcile,
      }
    ]
  },
  // {
  //   path: '/artcile',
  //   component: Artcile
  // }
]

const router = new VueRouter({
  routes
})


router.beforeEach((to, from, next)=>{
  if (to.path == '/login') {
    next()
  }
  if (!window.sessionStorage.getItem('token') || window.sessionStorage.getItem('token') == 'null' || window.sessionStorage.getItem('token') == '' || window.sessionStorage.getItem('token') == undefined) {
    next('/login')
  }
  next()
    });


export default router
